package Feb_15;

import java.io.*;
import java.net.InetAddress;
import java.net.Socket;

public class FileClient {
    public static void main(String[] args) {
        try {
            //启动服务
            Socket socket = new Socket(InetAddress.getByName("127.0.0.1"),8080);
            //输入字节流给服务器
            OutputStream outputStream =socket.getOutputStream();
            //读取本地图片
            FileInputStream fileInputStream = new FileInputStream(new File("src/Feb_15/File.txt"));
            //每次读取1024个字节
            byte[] bytes = new byte[1024];
            int length;

            while ((length=fileInputStream.read(bytes))!=-1){
                outputStream.write(bytes,0,length);
            }

            socket.shutdownOutput();
            InputStream inputStream = socket.getInputStream();
            bytes = new byte[1024];
            while ((length=inputStream.read(bytes))!=-1){
                String str = new String(bytes,0,length);
                System.out.println("发送图片："+str);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
